package com.yunwaikeji.gy_tool_library.widget.boxDialog;

import android.widget.LinearLayout;

import com.yunwaikeji.gy_tool_library.R;
import com.yunwaikeji.gy_tool_library.adapter.recycler.GYRecyclerAdapter;
import com.yunwaikeji.gy_tool_library.adapter.recycler.GYViewHolder;
import com.yunwaikeji.gy_tool_library.widget.GYButton;
import com.yunwaikeji.gy_tool_library.info.GYBaseInfo;

public class GYBoxDialogAdapter extends GYRecyclerAdapter<GYButton, GYViewHolder> {

    private final GYBoxDialog boxDialog;

    public GYBoxDialogAdapter(GYBoxDialog boxDialog) {
        super(R.layout.adapter_gy_box_dialog);
        this.boxDialog = boxDialog;
    }

    @Override
    protected void convert(GYViewHolder holder, GYButton gyButton) {
        LinearLayout linearLayout = (LinearLayout) holder.itemView;
        linearLayout.addView(gyButton);
        gyButton.getViewSet().setSizePx(GYBaseInfo.MATCH_PARENT, GYBaseInfo.MATCH_PARENT);
        int leftBottomRadius = boxDialog.getAllLinearLayout().getBackgroundBuilder().getRadiusLeftBottomPx();
        int rightBottomRadius = boxDialog.getAllLinearLayout().getBackgroundBuilder().getRadiusRightBottomPx();
        if (getData().size() == 1) {
            gyButton.getBackgroundBuilder().setRadiusLeftBottomPx(leftBottomRadius)
                    .setRadiusRightBottomPx(rightBottomRadius).build();
        } else {
            gyButton.getBackgroundBuilder().setRadiusPx(0).build();
            if (holder.getItemPosition() == 0) {
                gyButton.getBackgroundBuilder().setRadiusLeftBottomPx(leftBottomRadius).build();
            } else if (holder.getItemPosition() == getData().size() - 1) {
                gyButton.getBackgroundBuilder().setRadiusRightBottomPx(rightBottomRadius).build();
            }
        }
    }
}
